﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ComicBook.Data.IDataAdapters.Interfaces;
using ComicBook.Data.IDataAdapters.Adapters;
using ComicBook.DataModels;

namespace ComicBook.web.Controllers
{
    public class AddController : Controller
    {
        IComicBookAdapter _adapter;
        public AddController()
        {
            _adapter = new ComicBookAdapter();
        }
        public AddController(IComicBookAdapter adapter)
        {
            _adapter = adapter;
        }
        [HttpGet]
        public ActionResult AddComic()
        {
            return View();
        }
        [HttpPost]
        public ActionResult AddComic(string title, string image)
        {
            Comic comic = new Comic();
            comic.Title = title;
            comic.Image = image;
            comic = _adapter.AddComic(comic);
            return RedirectToAction("AddAuthor/"+comic.Id);
        }
        [HttpGet]
        public ActionResult AddAuthor(int? id)
        {
            return View(id);
        }
        [HttpPost]
        public ActionResult AddAuthor(string name, string image, int comicId)
        {
            Author author = new Author();
            author.Name = name;
            author.Image = image;
            author = _adapter.AddAuthor(author);

            AuthorComicBook acb = new AuthorComicBook();
            acb.AuthorId = author.Id;
            acb.ComicId = comicId;
            acb = _adapter.AddAuthorComicBook(acb);
            return Redirect("/Home/Index");
        }

	}
}